package com.atguigu.eduservice.controller;


import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduSubject;
import com.atguigu.eduservice.entity.subject.OneSubject;
import com.atguigu.eduservice.service.EduSubjectService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author thomasyang
 * @since 2023-12-08
 */

//@CrossOrigin
@RestController
@RequestMapping("/eduservice/subject")
public class EduSubjectController {

    @Autowired
    private EduSubjectService subjectService;

    //添加课程分类
    //获取上传过来文件，把文件内容读取出来
    @PostMapping("addSubject")
    public R addSubject(@RequestPart ("file") MultipartFile file){

         subjectService.saveSubject(file, subjectService);

         return  R.ok();
    }

    @ApiOperation(value = "获取全部课程列表")
    @GetMapping("getAllSubject")
    public R getSubject(){

       List<OneSubject> subjectList =  subjectService.getAllSubject();

       return R.ok().data(subjectList);

    }

}

